﻿using Pdelvo.Minecraft.Network;

namespace Pdelvo.Minecraft.Protocol.Packets
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks></remarks>
    public class PlayerListItem : Packet
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PlayerListItem"/> class.
        /// </summary>
        /// <remarks></remarks>
        public PlayerListItem()
        {
            Code = 0xC9;
        }

        /// <summary>
        /// Gets or sets the name of the player.
        /// </summary>
        /// <value>The name of the player.</value>
        /// <remarks></remarks>
        public string PlayerName { get; set; }
        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="PlayerListItem"/> is online.
        /// </summary>
        /// <value><c>true</c> if online; otherwise, <c>false</c>.</value>
        /// <remarks></remarks>
        public bool Online { get; set; }
        /// <summary>
        /// Gets or sets the ping.
        /// </summary>
        /// <value>The ping.</value>
        /// <remarks></remarks>
        public short Ping { get; set; }

        /// <summary>
        /// Receives the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="version">The version.</param>
        /// <remarks></remarks>
        public override void Receive(BigEndianStream reader, int version)
        {
            PlayerName = reader.ReadString16(16);
            Online = reader.ReadBool();
            Ping = reader.ReadShort();
        }

        /// <summary>
        /// Sends the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="version">The version.</param>
        /// <remarks></remarks>
        protected override void Send(BigEndianStream writer, int version)
        {
            writer.Write(Code);
            writer.Write(PlayerName);
            writer.Write(Online);
            writer.Write(Ping);
        }
    }
}